﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using RenChangYou.Model;

namespace DaoYou.Web
{
    public partial class _GuiderList : System.Web.UI.Page
    {
        private string Keyword
        {
            get 
            {
                if (Request["k"] != null)
                {
                    return HttpUtility.HtmlDecode(Request["k"].ToString());
                }

                return string.Empty;
            }
        }

        protected List<RenChangYou.Model.DY_GuiderInfo> GuideList = new List<RenChangYou.Model.DY_GuiderInfo>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.Keyword))
            {
                this.Page.Title = "导游信息 - 金牌导游网";
                this.Page.MetaKeywords = "导游，金牌导游，预订导游，推荐导游，专业导游";
                this.Page.MetaDescription = "金牌导游网是专门为您的出行推荐导游的专业网站，在这里您可以通过电脑或手机预订世界各地的当地专业导游，站内所有导游全部经过资质论证，身份核实，持导游证上岗。";
            }
            else
            {
                this.Page.Title = string.Format("{0}导游 - 金牌导游网", this.Keyword);
                this.Page.MetaKeywords = string.Format("{0}导游，预订{0}导游，推荐{0}导游，专业{0}导游", this.Keyword);
                this.Page.MetaDescription = string.Format("金牌导游网是专门为您的出行推荐导游的专业网站，在这里您可以通过电脑或手机预订{0}当地专业导游，站内所有导游全部经过资质论证，身份核实，持导游证上岗。", this.Keyword);
            }

            GetAllGuid();
        }

        private void GetAllGuid()
        {
            RenChangYou.BLL.DY_GuiderInfo bll = new RenChangYou.BLL.DY_GuiderInfo();

            string where = string.Empty;

            if (!string.IsNullOrWhiteSpace(this.Keyword))
            {
                where = string.Format(" UserName in (select UserName from dbo.DY_User with (nolock) where UserType = '1' and ( Province = '{0}' or City = '{0}' ) ) ", this.Keyword);
            }

            List<RenChangYou.Model.DY_GuiderInfo> list = bll.GetModelList(where);

            if (list == null || list.Count == 0)
            {
                where = " UserName in (select UserName from dbo.DY_User with (nolock) where UserType = '1') ";
                list = bll.GetModelList(where);
            }

            this.GuideList = list;
        }

        protected RenChangYou.Model.DY_User GetUserInfo(string username)
        {
             RenChangYou.BLL.DY_User bll = new RenChangYou.BLL.DY_User();
             return bll.GetModelByCache(username);
        }

        protected string GetUserShortIntroduction(string username)
        {
            RenChangYou.BLL.DY_GuideIntroduction bll = new RenChangYou.BLL.DY_GuideIntroduction();
            RenChangYou.Model.DY_GuideIntroduction model = bll.GetModelList(string.Format(" UserName = '{0}' and IsInUse = 1 ", username)).FirstOrDefault();

            if (model != null && !string.IsNullOrWhiteSpace(model.Introduction))
            {
                string s = RenChangYou.Common.StringPlus.NoHTML(model.Introduction);

                if (!string.IsNullOrWhiteSpace(s))
                    return s;
            }

            return "暂无介绍";
        }
    }
}
